package com.matthewmadson.util.configurator;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.apache.commons.cli.ParseException;

public class Example
{
	public static void main(String[] args) 
	throws ParseException, IOException
	{
		ConfigFile applicationConfigFile = new ConfigFile("app-settings");
		applicationConfigFile.setCommandLineOption("config", 1);
		applicationConfigFile.setExternalFileLocation("./config/app.properties", 2);
		applicationConfigFile.setInternalFileLocation("com.mmadson.utils.base.resources","app.properties", 1);
		applicationConfigFile.setRequired(false);
		
		ConfigFile logConfigFile = new ConfigFile("log-settings");
		logConfigFile.setCommandLineOption("log", 1);
		logConfigFile.setExternalFileLocation("./config/log.xml", 2);
		logConfigFile.setInternalFileLocation("com.mmadson.utils.base.resources", "log.xml", 3);
		logConfigFile.setRequired(true);
		
		ConfigFiles configFiles = new ConfigFiles();
		configFiles.add(applicationConfigFile);
		configFiles.add(logConfigFile);

		ConfigFileManager manager = ConfigFileManager.getManager();
		manager.parse(configFiles, args);
		
		if(manager.isLoaded("app-settings"))
			System.out.println(manager.getProperties("app-settings").get("test"));
		if(manager.isLoaded("log-settings"))
		{
			BufferedReader br = new BufferedReader(new InputStreamReader(manager.getInputStream("log-settings")));
			String line = null;
			while((line = br.readLine()) != null)
				System.out.println(">>"+line);
		}
	}

}
